"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Koa = require("koa");
var path = require("path");
var serve = require("koa-static");
var Router = require("koa-router");
var cors = require("koa2-cors");
var bodyParser = require("koa-bodyparser");
var router_1 = require("./router");
var router = new Router();
var app = new Koa();
app.use(bodyParser());
app.use(cors({
    origin: function (ctx) {
        var origin = ctx.request.header.origin;
        var allowHost = ['http://localhost:3001', 'http://localhost:8080'];
        for (var i = 0; i < allowHost.length; i++) {
            if ("" + origin === allowHost[i]) {
                return allowHost[i];
            }
        }
        return false;
    },
    allowMethods: ['GET', 'POST'],
    allowHeaders: ['Content-Type', 'Authorization', 'Accept', 'X-Custom-Header', 'anonymous'],
}));
app.use(serve(path.resolve('./static')));
router_1.default(router);
var host = 'localhost';
var port = 3002;
app.listen((function () {
    console.log('http://' + host + ':' + port);
    return port;
})());
app.use(router.routes()).use(router.allowedMethods());
